import { onMounted } from 'vue';

export function useSeo(meta: { title?: string; description?: string; keywords?: string }) {
	onMounted(() => {
		if (meta.title) document.title = meta.title;
		if (meta.description) setMeta('description', meta.description);
		if (meta.keywords) setMeta('keywords', meta.keywords);
	});
}

function setMeta(name: string, content: string) {
	let el = document.querySelector(`meta[name="${name}"]`) as HTMLMetaElement | null;
	if (!el) {
		el = document.createElement('meta');
		el.setAttribute('name', name);
		document.head.appendChild(el);
	}
	el.setAttribute('content', content);
}


